# -*- coding: utf-8 -*-
# (c) 2015 Mikel Arregi - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models
import odoo.addons.decimal_precision as dp


class move_quant_for_pick(models.Model):
    _name = 'move.quant.for.pick'
    _description = u"move上面挑选，并增加move的数量。用作生产投料明细上面的超投料"

    move_id = fields.Many2one('stock.move', u"投料")
    product_id = fields.Many2one('product.product', u"产品")
    location_id = fields.Many2one('stock.location', u"库位")
    quant_id = fields.Many2one('stock.quant', u"份",
                               domain="[('product_id', '=', product_id),('location_id', '=', location_id),('reservation_id', '=', False)]")
    quant_qty = fields.Float(u"份数量", related='quant_id.qty')
    lot_id = fields.Many2one('stock.production.lot', u"批次/序列号", related='quant_id.lot_id')
    pick_quant_qty = fields.Float(u'挑选数量', digits=dp.get_precision('Product Unit of Measure'), default=0.0)

    lot_uom = fields.Many2one('product.uom', u'辅助单位', related='lot_id.lot_uom')
    lot_uom_ratio = fields.Float(u'换算率', digits=(16, 4), related='lot_id.lot_uom_ratio')
    lot_lenth = fields.Char(u'全长', related='lot_id.lot_lenth')

    code = fields.Char(u"代码", size=10, related='lot_id.code')
    description = fields.Char(u"说明", size=20, related='lot_id.description')
    board_number = fields.Char(u"内部参考", size=20, related='lot_id.board_number')

    idle = fields.Boolean(u'呆滞', default=False, related='lot_id.idle')
    sale_type = fields.Selection([('0', u'内销'), ('1', u'外销')], u'销售类型', related='lot_id.sale_type')


class pack_quant_for_pick(models.Model):
    _name = 'pack.quant.for.pick'
    _description = u"pack上面挑选，并增加pack的完成数量。用作调拨单上面的超量调拨。用途一般用来作超领料"

    pack_id = fields.Many2one('stock.pack.operation', u"作业")
    product_id = fields.Many2one('product.product', u"产品")
    location_id = fields.Many2one('stock.location', u"库位")
    quant_id = fields.Many2one('stock.quant', u"份",
                               domain="[('product_id', '=', product_id),('location_id', '=', location_id),('reservation_id', '=', False)]")
    quant_qty = fields.Float(u"份数量", related='quant_id.qty')
    lot_id = fields.Many2one('stock.production.lot', u"批次/序列号", related='quant_id.lot_id')
    pick_quant_qty = fields.Float(u'挑选数量', digits=dp.get_precision('Product Unit of Measure'), default=0.0)

    lot_uom = fields.Many2one('product.uom', u'辅助单位', related='lot_id.lot_uom')
    lot_uom_ratio = fields.Float(u'换算率', digits=(16, 4), related='lot_id.lot_uom_ratio')
    lot_lenth = fields.Char(u'全长', related='lot_id.lot_lenth')

    code = fields.Char(u"代码", size=10, related='lot_id.code')
    description = fields.Char(u"说明", size=20, related='lot_id.description')
    board_number = fields.Char(u"内部参考", size=20, related='lot_id.board_number')

    idle = fields.Boolean(u'呆滞', default=False, related='lot_id.idle')
    sale_type = fields.Selection([('0', u'内销'), ('1', u'外销')], u'销售类型', related='lot_id.sale_type')
